import request from "./request.js";
// 註冊
export function register(params) {
	return request("/driver/user/register", "POST", params)
}
// 登錄
export function login(params) {
	return request("/driver/user/login", "POST", params)
}
// 驗證碼登錄
export function codeLogin(params) {
	return request("/driver/user/mobilelogin", "POST", params)
}
// 重置密碼
export function changePassword(params) {
	return request("/driver/user/resetpwd", "POST", params)
}
// 司機認證
export function approveDrive(params) {
	return request("/driver/user/auth", "POST", params)
}
// 上線
export function onelineSign(params) {
	return request("/driver/car/onelineSign", "POST", params)
}
// 获取订单
export function getOrderList(params) {
	return request("/driver/order/order_list", "POST", params)
}
// 我的愛車
export function myCars(params) {
	return request("/driver/car/my_cars", "POST", params)
}
// 我的邀請碼
export function myCode(params) {
	return request("/driver/user/invite_qrcode", "POST", params)
}
// 獲取客服信息
export function serviceInfor(params){
	return request('/api/index/service','POST',params)
}
// 添加車輛
export function addCar(params) {
	return request("/driver/car/car_add", "POST", params)
}
// 獲取個人信息
export function getMineInfor(params) {
	return request("/driver/user/index", "POST", params)
}
// 获取协议
export function getArticle(params) {
	return request("/api/index/article", "POST", params)
}
// 銀行卡列表
export function cardList(params) {
	return request("/driver/bank/index", "POST", params)
}
// 添加銀行卡
export function addCard(params) {
	return request("/driver/bank/add", "POST", params)
}
// 申請提現
export function toWithdraw(params) {
	return request("/driver/userFund/withdraw", "POST", params)
}
// 资金明细
export function getFundLog(params) {
	return request("/driver/user_fund/fund_log", "POST", params)
}
// 资金明细
export function getOrderLog(params) {
	return request("/driver/user_fund/order_log", "POST", params)
}
// 意见反馈
export function toFeedBack(params) {
	return request("/driver/index/feedback", "POST", params)
}
// 订单列表
export function orderList(params){
	return request("/driver/order/order_list",'POST',params)
}
// 订单详情
export function orderDetails(params){
	return request("/driver/order/order_detail",'POST',params)
}
// 地理位置反向编码
export function getNowAddress(latlng) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://maps.googleapis.com/maps/api/geocode/json',
			method: 'GET',
			data: {
				key:'AIzaSyBp7LF3tHEomcoYojzqArmIKYNuY1VL5CE',
				latlng:latlng,
				language:'zh-CN'
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				reject(err);
			},
			complete() {

			}
		});
	});
}
// 获取路径规划
export function getDirections(params) {
	return new Promise((resolve, reject) => {
		console.log(params);
		uni.request({
			url: 'https://maps.googleapis.com/maps/api/directions/json',
			method: 'GET',
			data: {
				key:'AIzaSyBp7LF3tHEomcoYojzqArmIKYNuY1VL5CE',
				mode:'driving',
				...params
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				reject(err);
			},
			complete() {

			}
		});
	});
}
// 搜索地址
export function selectAddress(params) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://maps.googleapis.com/maps/api/place/textsearch/json',
			method: 'GET',
			data: {
				key:'AIzaSyBp7LF3tHEomcoYojzqArmIKYNuY1VL5CE',
				language:'zh-CN',
				sensor:true,
				...params
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				reject(err);
			},
			complete() {

			}
		});
	});
}
export function getDistances(lat1, lng1, lat2, lng2) {
	var radLat1 = rad(lat1);
	var radLat2 = rad(lat2);
	var a = radLat1 - radLat2;
	var b = rad(lng1) - rad(lng2);
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
		Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * 6378.137; // EARTH_RADIUS;
	// 输出为公里
	s = Math.round(s * 10000) / 10000;

	var distance = s;
	var distance_str = "";

	if (parseInt(distance) >= 1) {
		;
		distance_str = distance.toFixed(2) + "km";
	} else {
		distance_str = (distance * 1000).toFixed(2) + "m";
	}
	return distance_str
}
//	角度转换成弧度
const rad = (d) => {
	return d * Math.PI / 180.00;
};